import { _decorator, Component, Node, Prefab, instantiate, Animation, Vec3, screen, Input, input, sys, Collider2D, Contact2DType, IPhysics2DContact, Sprite } from 'cc';
import { data } from '../../data';
import { G } from '../../G';
const { ccclass, property } = _decorator;

@ccclass('classicScene')
export class classicScene extends Component {

    private player: Node;
    private score: Node;

    start() {
        // 初始化
        G.startGame(this.node)
        // 制作分数
        this.score = G.gameRoot.scoreInit(this.node)
        // 制作玩家
        this.player = G.gameRoot.playerInit(this.node, data.playerSelected)
        // 玩家碰撞监听
        let collider = this.player.getComponent(Collider2D)
        if (collider) {
            collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this)
        }
    }

    update(deltaTime: number) {
        G.gameUpdate(this.player, this.node, this.score, "classic")
    }

    /**
     * 经典模式的玩家碰撞检测
     * @param self 
     * @param other 
     * @param contact 
     */
    onBeginContact(self: Collider2D, other: Collider2D, contact: IPhysics2DContact | null) {
        G.stopGame(this.node, this.player)
    }


}


